package com.cby.jetpack.sample.worker

import android.annotation.SuppressLint
import android.content.Context
import androidx.work.Data
import androidx.work.ListenableWorker
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.cby.util.lib.util.CbyLogUtils

/**
 * @description: SimpleWorker
 *
 * @author ChenBaoyang
 * @date 2021/10/11 10:33
 */
class SimpleWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {

    @SuppressLint("RestrictedApi")
    override fun doWork(): Result {
        CbyLogUtils.flog("简单任务")
        return Result.Success()
    }
}

class TransferDataWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams){

    override fun doWork(): Result {
        CbyLogUtils.flog("数据传输")
        val activityData = inputData.getString("data")
        val data = Data.Builder()
            .putString("data", activityData).build()
        return Result.success(data)
    }
}

class MoreWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams){

    override fun doWork(): Result {
        val activityData = inputData.getString("data")
        CbyLogUtils.flog("任务链", activityData)
        return Result.success()
    }
}


class PeriodicWork(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams){

    override fun doWork(): Result {
        CbyLogUtils.flog("周期性任务","执行完毕")
        return Result.success()
    }
}